#include"Commd.hpp"
#include"Fifo.hpp"
#include<unistd.h>
#include<iostream>
int main()
{
    //1. 生成钥匙
    key_t key = GetShmKeyOrDie();
    std::cout << "key: " << ToHex(key) << std::endl;


    //2. 获得shmid
    int shmid = GetShm(key,defaultsize);
    std::cout << "shmid: " << shmid << std::endl;
    //sleep(2);


    //3. 共享内存和进程挂接
    char *str  = (char*)ShmAttach(shmid);
    std::cout << "Attach shm success, addr: " << ToHex((uint64_t)str) << std::endl;
    //sleep(2);
    
    memset(str,0,defaultsize);
    syns syn;
    syn.OpenWriteOrDie();
    //可以通信了
    for(char c = 'A';c <= 'Z';c++)
    {
        str[c-'A'] = c;
        sleep(1);
        syn.wakeup();
    }



    //4. 取消内存和进程挂接
    ShmDetach(str);
    std::cout << "Detach shm success, addr: " << ToHex((uint64_t)str) << std::endl;
    sleep(5);
    return 0;
}